package com.qf.controller;

import com.qf.entity.User;
import com.qf.service.UserService;
import com.qf.service.impl.UserServiceImpl;
import com.qf.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping ResultVo list() {
        List<User> data = userService.list();
        return new ResultVo(200,"ok",data);
    }
    @PostMapping("/add")
    public ResultVo add(@RequestBody User user){
        List<User> list = userService.addUser(user);
        return new ResultVo(200,"OK",list);
    }
    @PostMapping("/edit")
    public ResultVo edit(@RequestBody User user) {
        userService.edit(user);
        return new ResultVo(200,"ok","修改成功");
    }

    @DeleteMapping("/delete")
    public ResultVo delete(Integer id) {
        userService.delete(id);
        return new ResultVo(200,"OK","删除成功");
    }
    @GetMapping("/findbyid")
    public ResultVo findById(Integer id){
        User user = userService.findbyid(id);
        return new ResultVo(200,"ok",user);
    }
}
